<!DOCTYPE html>
<html>
	<?php header('Content-Type: text/html; charset=utf-8');?>
	<head>
		<meta charset="UTF-8">
		<title>管理员管理</title>

		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8" />
		<link rel="shortcut icon" href="../images/titlelogo.png" type="image/x-icon" />
		<link rel="stylesheet" href="../css/font.css">
		<link rel="stylesheet" href="../css/xadmin.css">
		<script src="../js/jquery-3.3.1.min.js"></script>
		<script type="text/javascript" src="../lib/layui/layui.js" charset="utf-8"></script>
		<script type="text/javascript" src="../js/xadmin.js"></script>
		<!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
		<!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

		<!-- <script src="http://www.jq22.com/jquery/jquery-3.3.1.js"></script> -->

		<link href="../lib/layui/css/layui.css" type="text/css" rel="stylesheet">
		<script language="Javascript" src="../js/nicePage.js"></script>

		<?php $host="localhost";  //IP地址
$username="root";  //数据库用户名
$password="root"; //数据库密码
$port=3306;       //端口
$dbname="xops"; //数据库名称
//连接数据库
$con = mysqli_connect($host.":".$port,$username,$password,$dbname);

if ($con->connect_error) {
   die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error);

}
 $l=5;
$con->query("set names utf8"); // 设置输出字符集
         $sql_se="Select * from `admin`  ";
         $result_se=mysqli_query($con,$sql_se);
         $count_se= mysqli_num_rows($result_se);
				  $newru=[];
     while ($rowru=mysqli_fetch_assoc($result_se)) {
        $newru[]=$rowru;
      }
      

?>
	</head>
	<style>
		* { margin: 0; padding: 0; }
    body { font-family: 'Microsoft Yahei'; font-size: 18px; background-color: #f8f8f8; }

    #table2 {
      width: 1200px;
      margin: 40px auto 0;
      border-collapse: collapse;
      background-color: #fff;
    }
    #table td,
    #table th {
    /*  padding: 0.75em 1.5em; */
    }
    #table thead {
      color: #fff;
      background-color: #31bc86;
    }
    #table thead th {
      text-align: left;
    }
    #table tbody {}
    #table tbody tr {
      border-bottom: 2px dashed #000;
      cursor: default;
      transition: all .125s ease-in-out;
    }
    #table tbody tr:hover {
      background-color: cornflowerblue;
    }
	
    #table tbody tr.event-bgColor {
      background-color: rgba(255, 192, 203, .2);
    }
    #table tbody tr.default-bgColor {
      background-color: #fff;
    }
    #table tbody tr.hover-bgColor {
      background-color: rgba(255, 192, 203, .8);
    }
    #table tbody tr.selected-bgColor {
      background-color: rgb(255, 192, 203);
    }
    
    #selectAll {
      margin-left: -4px;
    }
    .checkbox {
      -webkit-user-select: none;
      -moz-user-select: none;
      -ms-user-select: none;
      -o-user-select: none;
      user-select: none;
    }
	
	.content{
			outline-style: none ;
			    border: 0px solid #ccc;
			    bordHer-radius: 3px;
			    font-size: 20px;
	            width: 100%;
			padding:5px 0px; 
	        margin: -10px 0px;
			color: blue;
		}
	
	.content2{
	    border-color: red;
	    outline: 0;
	    -webkit-box-shadow: inset 0 1px 1px  red,0 0 8px  yellow;
	    box-shadow: inset 0 1px 1px  red,0 0 8px  yellow;
	}
	
  </style>
	<body class=" layui-fluid" onload="a()">

		<!-- <div id="demo21"></div> -->
		<!-- <script src="../lib/layui/layui.js"></script> -->
		<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

		<script>
		// 	$(document).ready(function(){
		// 
		// 	$(".layui-form-checkbox").attr("checked", true);        
		// 	
		// })
             // setInterval("a()","1000");
			function a(){
			 // $.post("http://localhost:86/HBuilder/xops/Back.php",{
				// 				     
				// 				     type:"Config",
				// 					 operation:"adurl",
				// 				
				// 					 token:"1ab66e59325257b60b971d4afa1505ce"
				// 				     
				// 				   },function(data,status){
				// 					
				// 			  // alert("data:"+typeof(data)+" "+data.length+" "+data) 
				// 					   if(data==1){
				// 						   alert("suc1") 
				// 	window.location.reload(); 
				// 							 alert("suc2") 
				// 					   }
				// 					 
				// 					   
				// 					   })
		  }
 
		

			
		</script>
		<script>
			arr_id=[];

			jsonttp='[';
 	        
            	<?php for($i=0;$i<$count_se;$i++){ 
            	$value_se=$newru[$i]['id'];
				$value_da=$newru[$i]['account'];
				$value_pd=$newru[$i]['password']; 
				$value_tel=$newru[$i]['tel']; 
				$value_dt=$newru[$i]['datetime'];
				$value_sex=$newru[$i]['sex'];
				$tt=$i+1;
				?>
				$p=1;
				 arr_id.push(<?php echo $value_se;?>);
            jsonttp+="{'1':'<input id=<?php echo $tt;?>box type=\"checkbox\"  value=\"<?php echo $value_se;?>\" name=\"test\"  style=\"width:16px;height:16px;\" class=\"layui-form-checkbox\" />'+'<span style=\"font-size:20px;margin-left:5px;\"/>'+ ($p++)+'</span>','5':'<input value=<?php echo $value_tel;?> class=\"content\" style=\"margin:0px;\" readonly=\"readonly\" id=<?php echo $tt;?>tel  onchange=\"change(this.id)\" />','2':'<input value=<?php echo $value_da;?> class=\"content\" style=\"margin:0px;\" readonly=\"readonly\" id=<?php echo $tt;?>at  onchange=\"change(this.id)\" />','3':'<input type=\"password\" value=<?php echo $value_pd;?> class=\"content pwd\" style=\"margin:0px;\" readonly=\"readonly\" id=<?php echo $tt;?>pd  onchange=\"change(this.id)\" />','6':'<span style=\"font-size:20px;margin-left:5px;\"><?php echo $value_dt;?></span>','4':'<input value=<?php echo $value_sex;?> class=\"content\" style=\"margin:0px;\" readonly=\"readonly\" id=<?php echo $tt;?>sex  onchange=\"change(this.id)\" />'},";
  
            <?php }?>
              
		
			jsontt="[";
			jsontt="<?php for($i=0;$i<2;$i++){} 
			 ?>";
		
			jsonttp=jsonttp.substring(0,jsonttp.length-1)+"]";	
	     
			 jsont = eval("(" + jsonttp + ")");
	
			// 	//nameList与widthList的数组长度要一致
			var nameList = ['<input type=\"checkbox\"   id=\"it\"  style=\"width:16px;height:16px;\" onclick=\"cb()\"  class=\"layui-form-checked\"/> <span style=\"font-size: 20px;\">序号</span>',  '<span style=\"font-size: 20px;\">用户名</span>', '<span style=\"font-size: 20px;\">密码</span>','<span style=\"font-size: 20px;\">性别</span>', '<span style=\"font-size: 20px;\">电话</span>','<span style=\"font-size: 20px;\">注册时间</span>'] //table的列名
			var widthList = [30, 50, 120,30,80,80] //table每列的宽度
							$(".layui-form-checkbox").prop("checked",function(){
											console.log("fds")
			    return true;//函数返回true或false
			});
			
		function cb(){
			//获取到点击全选的那个复选框的id
			      var one=document.getElementsByName("test");//获取到复选框的名称  
							// alert("h:"+ $("input[type='checkbox']").children.length);
						
// 							$(".layui-form-checkbox").prop("checked",function(){
// 								console.log("fds")
//     return true;//函数返回true或false
// });
  //                           for(var i in jsont)
		// 					for(var j in jsont[i])
		// 					{
		// 						// if(i==0){
		// 							
		// 						// }
		// 						// console.log("qq:",i," "," ",j," ",(jsont[i][j]))
		// 						if(j=1){
		// 							
		// 						
		// 						po=jsont[i][1];
		// 						 po3=po.replace("layui-form-checkbox\"" ,"layui-form-checkbox\" checked")
		// 						// alert(po3);
		// 						jsont[i][1]=po3;
		// 						}
		// 					}
		// 				
		// 					po='<input id=1box type="checkbox"  value="211" name="test"  style="width:16px;height:16px;" class="layui-form-checkbox" /><span style="font-size:20px;margin-left:5px;"/>1</span>';
		// 					 var pos=po.indexOf("layui-form-checkbox");
		// 					 var pos2=po.indexOf("span");
		// 					 po3=po.replace("layui-form-checkbox\"" ,"layui-form-checkbox\" checked")
  //       // alert(po3);
		// jsont[0][1]=po3;
		// alert("p2:"+ " "+jsont[0][1])
							
				 all=document.getElementById("it");
			      if(all.checked==true){//因为获得的是数组，所以要循环 为每一个checked赋值
			          for(var i=0;i<one.length;i++){
			              one[i].checked=true;
			          }
			 
			      }else{
			          for(var j=0;j<one.length;j++){
			              one[j].checked=false;
			          }
			      }
		
		}

		
			
				
				 	nicePage.setCfg({
				 		table: 'table',
				 		bar: 'pageBar',
				 		limit:10,
				 		color: '#1E9FFF',
				 		layout: ['count', 'prev', 'page', 'next', 'limit', 'skip','refresh']
				 	});
				
				 p=[];
			
				ge=[];
	
			function change(event){
				ge.push(event)
			
			}
 function btn(){
		  
		len=$("#bn").val().length;
		 var str=$("#bn").val().substring(1,3);
		// alert("q:"+len+" "+str.length)
		 if(str=="编辑"){
			 // alert("111")
			   $(".pwd").removeAttr('type')
			 $(".content").removeAttr('readonly')
			   $("#bn").val("保存");
		 $(".content").addClass('content2',true)
		 }else{
			 // alert("222")
			   $(".pwd").attr('type',"password")
			 $(".content").attr('readonly',true)
			  $(".content").removeClass('content2')
			   $("#bn").val("编辑");
			   var array = [];
			    arr_value=[];
			   for (var i = 0; i < ge.length; i++) {
			       if (array .indexOf(ge[i]) === -1) {
			           array .push(ge[i])
					   // alert("ki:"+i+" "+ge[i])
					   arr_value.push($("#"+ge[i]).val())
			       }
			   }
			   if(array.length>0){
			   	 // alert("结果："+array.join(",")+ " <br/>"+arr_value.join(",")+"<br/>"+arr_id.join(","))
				 $.post("http://localhost:86/HBuilder/xops/Back.php",{
					     
					     type:"Admin",
						 operation:"update",
					     account:array.join(","),
						 password:arr_value.join(","),
						 phone:arr_id.join(","),
						 token:"1ab66e59325257b60b971d4afa1505ce"
					     
					   },function(data,status){
						   
						   obj=JSON.parse(data);
						   // alert("data:"+data);
						   if(obj.code==200){
							     layer.msg('保存成功!',{icon:1,time:1500});
						   }else if(obj.code==202){
							    layer.msg('保存失败!',{icon:1,time:1500})
						   }
						   })
		 }}
		 }
			 			</script>

		<div style="margin-top: 3%;margin-left: 2%;margin-right: 3%;">
			<div class="layui-form layui-col-md12 x-so">
				<button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>删除</button>
				<button class="layui-btn " onclick="x_admin_show('添加用户','./admin-add.html',600,400)"><i class="layui-icon"></i>添加</button>
				<input type="button" value="&#xe642;编辑" class="layui-btn layui-icon" id="bn" onclick="btn()" /> &nbsp;&nbsp;
				<input type="text" name="username" placeholder="关键字" autocomplete="off" class="layui-input" id="look">
				<button class="layui-btn" lay-submit="" lay-filter="sreach" onclick="look()"><i class="layui-icon">&#xe615;</i></button>
				<span class="layui-input-inline">
					<select name="cateid">
						<option>用户名</option>
						<option>密码</option>
						<option>性别</option>
						<option>电话</option>
						<option>注册时间</option>
					</select>
				</span>
				<button class="layui-btn"  id="btn3"><i class="iconfont">&#xe69e;</i>&nbsp;导入</button> &nbsp;&nbsp;
				<button class="layui-btn"><i class="iconfont">&#xe69e;</i>&nbsp;导出</button> &nbsp;&nbsp;
				<button class="layui-btn"><i class="iconfont">&#xe69e;</i>&nbsp;下载模板</button> &nbsp;&nbsp;
				
				<span>
					<a class="layui-btn layui-btn-primary layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);"
					 title="刷新">
						<i class="layui-icon" style="line-height:38px">ဂ</i></a>
				</span>
			</div>

			<div id="dt">
				<div id="table"></div>
				<div id="pageBar"></div>
			</div>


			<div class="x-body">
				<div class="layui-row">

				</div>

			
 
			</div>
		</div>


		<script>
			
			$("#btn3").click(function(){
				if(!$("#btn3").attr ("onclick")){
				
						$("#btn3").attr("onclick","x_admin_show('添加用户','./admin-add.html',600,400)");
						$('#btn3').trigger("click");
				}
			
				
			})
			
			function look() {
				var look = $("#look").val();
				// alert("dfs:"+look+" "+arr_id.join(","))

				$('tbody ').children().eq(1).css({
					'background-color': 'red'
				})

				$.post("http://localhost:86/HBuilder/xops/Back.php", {

					type: "Admin",
					operation: "searchAt",

					token: "1ab66e59325257b60b971d4afa1505ce"

				}, function(data, status) {
					// alert("data:"+data)
				})
			}
			layui.use('laydate', function() {

			});


			/*用户-删除*/
			function member_del(obj, id) {
				layer.confirm('确认要删除吗？', function(index) {
					//发异步删除数据
					$(obj).parents("tr").remove();
					layer.msg('已删除!', {
						icon: 1,
						time: 1000
					});
				});
			}


			function delAll(argument) {


				var id = document.getElementsByName('test');
				var value = new Array();
				for (var i = 0; i < id.length; i++) {
					if (id[i].checked)
						value.push(id[i].value);
				}
				if (value.length != 0) {
					layer.confirm('确认要删除吗？', function(index) {
						//捉到所有被选中的，发异步进行删除
						// for(var p=0;p<value.length;p++){
						// 	jsont.splice(parseInt(jsont[p]-1),1)
						// 	alert("gg:"+jsont.length)
						// }

						$.post("http://localhost:86/HBuilder/xops/Back.php", {

							type: "Admin",
							operation: "del",
							account: value.join(','),

							token: "1ab66e59325257b60b971d4afa1505ce"

						}, function(data, status) {
							obj = JSON.parse(data);
							// alert("pp:" + data)
							if (obj.code == 200) {

								// arr_ss=obj.data.split(",");
								// alert("uu:"+arr_ss.length+" "+arr_ss[0])
								// for(var j=0;j<arr_ss.length;j++){
								// 	jsont.splice(parseInt(arr_ss[j]-1),1)
								// 	alert("gg:"+jsont.length)
								// }

								// $("#table").load(location.href+" #table");
								layer.alert('删除成功！', {
									icon: 1
								}, function(index) {
									//发异步删除数据

									yu();

								});

								function yu() {
									window.location.href = "javascript:location.reload()";

								}

							} else {
								layer.msg('删除失败', {
									icon: 1
								});
							}

						})



						// $(".layui-form-checked").not('.header').parents('tr').remove();
					});
				} else {
					layer.msg('您未选择删除数据！', {
						icon: 5
					});
				}
			}
		</script>

	</body>

</html>
